#coding=gbk
import misc
import root
import pysrv
import msg
import PyMsg
import zone_config
import handler
accountData = zone_config.ACCOUNT_DATAS[0]
ACCOUNT_PORT = accountData[2]

class AccountServer(pysrv.PyServerDelegate):
    def goInit(self,port):
        self.init(port)
    def msgParseContent(self,id,content):
        print("AccountServer::msgParse",content)
        nullcmd = PyMsg.getmsg(msg.nullmsg)
        nullcmd.parse(content)
        session = handler.Session(id,self.getPeerIp(id),self.getPeerPort(id),self,handler.SERVER)
        handler.Handler().parse(session,nullcmd.cmd,nullcmd.para,content)

    def newTCPTask(self,id):
        nullCmd = PyMsg.getmsg(msg.nullmsg)
        self.sendString(id,nullCmd.stream())
        pass
    def taskDestroyed(self,id):
        pass

class AccountClient(pysrv.PyClientDelegate):
    def goInit(self):
        self.init(accountData[1],accountData[2])
    def connectGet(self):
        loginmsg = PyMsg.getmsg(msg.loginMsg)
        loginmsg.content = "hel"
        self.sendString(loginmsg.stream())
    def msgParseContent(self,content):
        nullcmd = PyMsg.getmsg(msg.nullmsg)
        nullcmd.parse(content)
        session = handler.Session(id,self.getPeerIp(),self.getPeerPort(),self,handler.CLIENT)
        handler.Handler().parse(session,nullcmd.cmd,nullcmd.para,content)
        print("AccountClient::msgParseContent",content,self.getPeerIp(),self.getPeerPort())
    def connectLoss(self):
        pass